﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Player : Character
{
	protected override void Awake ()
	{
		base.Awake ();
		DontDestroyOnLoad(this);
	}

	protected override void Start()
	{
		base.Start();
	}
	
	public override bool ActivateInteractive()
	{
		bool firstActivation = base.ActivateInteractive();
		if (firstActivation)
		{
			GameObject obj = ScreensManager.Instance.ShowPopup(PopupID.Popup_Storyline);
			obj.GetComponent<StorylinePopup>().Init(this);
			//GameCamera.Instance.SetZoom(trans);
		}

		return firstActivation;
	}

	protected override void FingerClick()
	{
		HUDScreen.Instance.SetupCharacter(this);
	}

	public void SwitchEquipped(UseableInfo _info)
	{
		GetInfo<CharacterInfo>().SwitchEquipped(_info);
		CharacterModified();
	}

	public bool CanDropItem()
	{
		return Area.AroundTile(currentTile).Count > 0;
	}

	public void DropItem(InteractiveInfo _info)
	{
		List<Tile> around = Area.AroundTile(currentTile);
		if (around.Count > 0 && GetInfo<CharacterInfo>().DropItem(_info))
		{
			FloorManager.Instance.SpawnInteractive(_info, around[0].transform);
			CharacterModified();
		}
	}

	public bool HasKey(DoorID _id)
	{
		foreach (InteractiveInfo content in GetInfo<CharacterInfo>().contents)
		{
			KeyInfo key = content as KeyInfo;
			if (key && key.door == _id)
			{
				return true;
			}
		}

		return false;
	}

	public void UseKey(DoorID _id)
	{
		foreach (InteractiveInfo content in GetInfo<CharacterInfo>().contents)
		{
			KeyInfo key = content as KeyInfo;
			if (key && key.door == _id)
			{
				GetInfo<CharacterInfo>().contents.Remove(content);
				break;
			}
		}
	}
}
